package com.taoge.p4.common.constants;

/**
 * 用户信息上下文
 */
public class UserContext {
    private static ThreadLocal<UserInfo> userThreadLocal = new ThreadLocal<>();

    public static void set(UserInfo userInfo) {
        userThreadLocal.set(userInfo);
    }

    public static UserInfo get() {
        return userThreadLocal.get();
    }

    public static Long getUserId() {
        UserInfo userInfo = userThreadLocal.get();
        if (userInfo == null) {
            return null;
        }
        return userInfo.getId();
    }

    public static void remove() {
        userThreadLocal.remove();
    }
}
